from pages.basePage3 import BasePage
from selenium.webdriver.common.action_chains import ActionChains
import time
from config.setting import host_port
# 定位层
class Elment_Now_parking(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/property/index.html")
    # 定位车辆管理
    def elment_car(self):
        return self.driver.find_element_by_xpath('/html/body/div[2]/div[1]/div/div[4]/div[1]/div[1]')

    # 定位现泊车信息
    def elment_now_parking(self):
        return self.driver.find_element_by_id('_easyui_tree_9')

     # 定位表单
    def elment_biaodan(self):
        a = self.driver.find_element_by_xpath('//div[@id="testIframe"]/div[2]/div[2]/div/iframe')
        return a
    # 定位增加按钮
    def elment_add(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/a[1]')
    # 定位汽车编号
    def elment_num(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input1"]')
    # 定位租客id
    def elment_id(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input2"]')
    # 定位汽车牌照
    def elment_licence(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位汽车类型
    def elment_cartype(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')

    # 定位增加
    def elment_add_end(self):
        return self.driver.find_element_by_xpath('/html/body/div[3]/div[3]/a[1]')
    # 定位下拉框
    def elment_chaxun_type(self):
        return self.driver.find_element_by_xpath('//*[@id="tb"]/span/a')
    # 定位输入内容框
    def elment_input(self):
        return self.driver.find_element_by_xpath('//*[@id="_easyui_textbox_input6"]')
    # 定位查询按钮
    def elment_chaxun_end(self):
        return self.driver.find_element_by_xpath('/html/body/div[3]/div[3]/a[1]/span')
    # 定位捕获文本
    def elment_chaxun_text(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]')


    # 定位删除按钮
    def elment_delete(self):
        return self.driver.find_element_by_xpath('//*[@id="tb"]/a[2]')
#     定位选择车辆框
    def elment_cares(self):
        return self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[1]/div/input')
# 定位修改按钮
    def elment_update(self):
        return self.driver.find_element_by_xpath('//*[@id="tb"]/a[3]/span')
# 定位车辆状态
    def elment_carstate(self):
        return self.driver.find_element_by_xpath('//*[@id="fm"]/div[5]/span/span/a')
# 定位提交修改按钮
    def elment_update_end(self):
        return self.driver.find_element_by_xpath('//*[@id="dlg-buttons"]/a[2]')

# 操作层
class Opion_Now_parking(Elment_Now_parking):
    def __init__(self):
        Elment_Now_parking.__init__(self)

    #     点击车辆相关
    def click_car(self):
        self.elment_car().click()

    #     点击现泊车信息
    def click_now_parking(self):
        self.elment_now_parking().click()

    #     切换表单
    def get_biaodan(self):
        a = self.elment_biaodan()
        return self.driver.switch_to.frame(a)

    #     点击增加按钮
    def click_add(self):
        self.elment_add().click()
    #输入汽车编号
    def input_num(self,num):
        return self.elment_num().send_keys(num)
    #输入租客id
    def input_id(self,id):
        return self.elment_id().send_keys(id)

    #输入汽车牌照
    def input_licence(self,licence):
        return self.elment_licence().send_keys(licence)

    # 输入汽车类型
    def input_cartype(self,cartype):
        return self.elment_cartype().send_keys(cartype)

#     点击增加
    def click_add_end(self):
        self.elment_chaxun_end().click()
# 获取查询文本
    def chaxun_text(self):
        return self.elment_chaxun_text().text
# 选择查询类型
    def select_chaxun_type(self):
        ActionChains(self.driver).move_to_element(self.elment_chaxun_type()).perform()  # 悬停
        time.sleep(1)
        return self.driver.find_element_by_xpath('/html/body/div[6]/div[4]/div').click()
# 输入查询的车牌
    def input_chaxun_licence(self,car_licence):
        return self.elment_input().send_keys(car_licence)
# d点击选定车辆
    def click_cares(self):
        self.elment_cares().click()
# 点击修改
    def click_update(self):
        self.elment_update().click()
# 修改车辆状态
    def click_carstate(self):
        self.elment_carstate().click()
        self.driver.find_element_by_xpath('//*[@id="_easyui_combobox_i1_1"]')
# 点击提交修改按钮
    def click_update_end(self):
        self.elment_update_end().click()
# 点击删除
    def click_delete(self):
        self.elment_delete().click()
# 业务层
class Apply_Now_parking(Opion_Now_parking):
    def __init__(self):
        Opion_Now_parking.__init__(self)
    def add_car(self,num,id,licence,cartype):
        self.click_car()
        self.click_now_parking()
        self.get_biaodan()
        self.click_add()
        self.input_num(num)
        self.input_id(id)
        self.input_licence(licence)
        self.input_cartype(cartype)
        self.click_add_end()
        b=self.chaxun_text()

        return b
    def select_car(self,car_licence):
        self.click_car()
        self.click_now_parking()
        self.get_biaodan()
        self.select_chaxun_type()
        self.input_chaxun_licence(car_licence)
        c=self.chaxun_text()

        return c
    def update_car(self,car_licence):
        self.select_car(car_licence)
        self.click_cares()
        self.click_update()
        self.click_carstate()
        self.click_update_end()
        d = self.chaxun_text()

        return d
    def delete_car(self,car_licence):
        self.select_car(car_licence)
        self.click_cares()
        self.click_delete()
        e = self.chaxun_text()

        return e
if __name__ == '__main__':
    Apply_Now_parking().update_car("陕C100003")
    # Apply_Now_parking().add_car(511, "03703044-1027-4b8f-924c-bf19292a34c9", "陕C100152", "小型")
